import os
import pandas as pd
import numpy as np
from sklearn.preprocessing import MinMaxScaler, StandardScaler


def loaddata(turbine_id=1, path="/home/duxiangyu/data/turbine_data/data_with_turbine_features/processed_data"):
    data = pd.read_csv(getpath(path, turbine_id))
    input_size = len(data.columns)
    return input_size, data


def getpath(path, turbine_id):
    return os.path.join(path, f'WuXingLing_WuXingLing{turbine_id:03d}_20231105000000_20231107000000_SCADA温数据.csv')


def loadradar(datapath='/root/radar_data_rate.csv', source_cols=['NacWdSpdFltS', 'CnvW400v', 'WecPlcSt', 'NacWdDir1'], target_cols=['RadWdSpd1']):
    data_df = pd.read_csv(datapath)
    source_df = data_df[source_cols]
    source_df['u'] = np.cos(np.radians(source_df['NacWdDir1'])) * source_df['NacWdSpdFltS']
    source_df['v'] = np.sin(np.radians(source_df['NacWdDir1'])) * source_df['NacWdSpdFltS']
    source_df.drop(['NacWdDir1'], axis=1)
    target_df = data_df[target_cols]
    return len(source_df.columns), pd.concat([source_df, target_df], axis=1)


def normalize(data_df):
    column_names = data_df.columns
    scalar = StandardScaler()
    data_df = scalar.fit_transform(data_df)
    data_df = pd.DataFrame(data_df, columns=column_names)
    return data_df, scalar


def resample(df):
    df['RadWdSpd1'] -= df['NacWdSpdFltS']



if __name__ == '__main__':
    data_df = loadradar()
    data_df, scalar = normalize(data_df)
    print(scalar.mean_, scalar.scale_)